import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _isFunction from "lodash/isFunction";
import _forEach from "lodash/forEach";

var _dec, _class;

/**
 * FieldProp.js
 * @date 2019-01-04
 */
import React from 'react';
import { Form, Input, Divider, Checkbox } from 'antd';
// import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
var FieldProp = (_dec = Form.create({
  fieldNameProp: null,
  onValuesChange: function onValuesChange(props, changedValues, allValues) {
    if (_isFunction(props.onValuesChange)) {
      props.onValuesChange(props, changedValues, allValues);
    }
  }
}), _dec(_class = /*#__PURE__*/function (_React$Component) {
  _inherits(FieldProp, _React$Component);

  var _super = _createSuper(FieldProp);

  function FieldProp() {
    var _this;

    _classCallCheck(this, FieldProp);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {};
    return _this;
  }

  _createClass(FieldProp, [{
    key: "render",
    value: // 防止第一次 state 是空报错
    function render() {
      var field = this.props.field;
      var propValues = {};

      _forEach(field.config, function (prop) {
        propValues[prop.attributeName] = prop.value;
      });

      return /*#__PURE__*/React.createElement(Form, null, this.renderFieldCommonProps(propValues), /*#__PURE__*/React.createElement(Divider, null), this.renderFieldTypeProps(propValues));
    }
  }, {
    key: "renderFieldCommonProps",
    value: function renderFieldCommonProps() {
      var _this$props = this.props,
          form = _this$props.form,
          field = _this$props.field;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, {
        key: "fieldName",
        label: "\u7F16\u7801"
      }, form.getFieldDecorator('fieldName', {
        initialValue: field.fieldName,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.ui.field.fieldName').d('编码')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        disabled: true
      }))), /*#__PURE__*/React.createElement(Form.Item, {
        key: "fieldLabel",
        label: "\u6807\u9898"
      }, form.getFieldDecorator('fieldLabel', {
        initialValue: field.fieldLabel
      })( /*#__PURE__*/React.createElement(Input, null))));
    }
  }, {
    key: "renderFieldTypeProps",
    value: function renderFieldTypeProps(propValues) {
      var field = this.props.field;
      var renderFunc = "renderFieldType".concat(field.componentType, "Props");

      if (_isFunction(this[renderFunc])) {
        return this[renderFunc](propValues);
      }

      return null;
    } // render other fields

  }, {
    key: "renderFieldTypeTabPaneProps",
    value: function renderFieldTypeTabPaneProps(propValues) {
      var form = this.props.form;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, null, form.getFieldDecorator('forceRender', {
        initialValue: propValues.forceRender
      })( /*#__PURE__*/React.createElement(Checkbox, {
        checkedValue: true,
        unCheckedValue: false
      }, "\u5F3A\u5236\u6E32\u67D3"))));
    } // render other fields

  }]);

  return FieldProp;
}(React.Component)) || _class);
FieldProp.displayName = 'DynamicTabs(FieldProp)';
export default FieldProp;